#!/usr/bin/python3
# coding=utf-8
import sys
import os
import json
import random

class CpingDeamon(object):
    def __init__(self, f):
        super(CpingDeamon, self).__init__()
        self._file = f

    def proc(self):
        dPing = {"stat": None, "seq": []}
        for l in self._file.readlines():
            obj = json.loads(l)
            if "stat" in obj:
                dPing['stat'] = obj["stat"]
            else:
                dPing["seq"].append(obj)
        s = json.dumps(dPing, indent=4)
        print(s)

if __name__ == "__main__":
    fname="/tmp/pingtrace_argv_"+str(random.random())
    f=open(fname,"w+")
    f.write(sys.argv[1])
    f.close()
    f=open(fname,"r")
    c = CpingDeamon(f)
    c.proc()
    f.close()
    os.remove(fname)
